/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author anhtai
 */
public class DBConnection {

    private String serverURL = "localhost";//localhost or 127.0.0.1;
    private int serverPort = 1433;
    private String databaseName = "NewsPageAgency";
    private String username = "sa";
    private String password = "danganhtai";
    private Connection conn;

    public void openConnect() throws ClassNotFoundException, SQLException {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        conn = DriverManager.getConnection("jdbc:sqlserver://" + serverURL + ":" + serverPort + ";databaseName=" + databaseName, username, password);
    }

    public void closeConnect() throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }
    
    public static void main(String [] args) throws ClassNotFoundException, SQLException
    {
        DBConnection db =  new DBConnection();
        db.openConnect();
        db.closeConnect();
    }

    public Connection getConn() {
        return conn;
    }

    public void setConn(Connection conn) {
        this.conn = conn;
    }
    
}
